﻿using System;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Drawing;
/// <summary>
/// Summary description for CommonRepository
/// </summary>
public class CommonRepository
{
	public CommonRepository()
	{
		
	}

    public static void ExportToExcel(DataTable dtClientReg,String categoryName)
    {
        string fileName = "attachment;filename=" + categoryName + "_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xls";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("content-disposition", fileName);
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.ContentType = "application/excel";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        GridView gvClientReg = new GridView();

        gvClientReg.HeaderStyle.BackColor = Color.FromName("#11459E");
        gvClientReg.HeaderStyle.Font.Bold = true;
        gvClientReg.HeaderStyle.Font.Name = "Arial";
        gvClientReg.HeaderStyle.Font.Size = FontUnit.XSmall;
        gvClientReg.HeaderStyle.ForeColor = Color.FromName("#E1E8F5");


        gvClientReg.DataSource = dtClientReg;
        gvClientReg.DataBind();

        gvClientReg.RenderControl(htmlWrite);
        HttpContext.Current.Response.Write(stringWrite);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
    }
}